import { mapActions } from 'vuex';
export default {
    props: {
        // 分享链接地址，不填则使用当前页面地址
        share: {
            type: String,
            default: '',
        },
        // 本条数据的主键
        rowguid: {
            type: String,
            default: '',
        },
        // 本条数据的类型（文章、文件等）
        type: {
            type: String,
            default: '',
        },
    },
    computed: {
        // 点赞数据
        likedinfo() {
            return this.data.likedinfo || {};
        },
        //收藏数据
        collectinfo() {
            return this.data.collectinfo || {};
        },
    },
    methods: {
        ...mapActions({
            showLogin: 'global-dialog/showLogin',
        }),
        likeHandler() {
            var url = '';

            if (this.likedinfo.isoperated) {
                // 已点过赞，本次操作应取消点赞

                url = `${this.$store.state.api.tbUrl}/liked/off.json`;
            } else {
                // 未点过赞，本次操作应点赞
                url = `${this.$store.state.api.tbUrl}/liked/on.json`;
            }

            this.$post(url, {
                objectguid: this.rowguid,
                objecttype: this.type,
            }, data => {
                this.data.likedinfo = data;

                this.$emit('like', data.isoperated);
            });
        },
        collectHandler(val) {
            const SERIAL_CODE = this.$cookies.get('SERIAL_CODE');
            const that = this;

            let fun  = function(){
                var url = `${that.$store.state.api.tbUrl}/document/doccollect.json`;
                var bj = '';
                if (that.collectinfo.isoperated) {
                    // 已收藏，本次操作应取消收藏
                    bj = '0'
                } else {
                    // 未收藏，本次操作应收藏
                    bj = '1'
                }

                that.$post(url, {
                    guid: that.rowguid,
                    bj: bj,
                    objectname: val.docname,
                }, data => {
                    that.data.collectinfo = data;

                    that.$emit('collect', data.isoperated);
                });
            }

            if (!SERIAL_CODE) {
                this.showLogin(() => {
                    fun();
                });
            }else{
                fun();
            }

        },
    },
    mounted() {
        
    }
};